package com.ithei.多线程第二天.可见性;

public class Demox {
    public static void main(String[] args) throws InterruptedException {
        Gril gr = new Gril();
        gr.start();
        while (true) {
            synchronized ("asd") {
                if (Gril.money < 10) {
                    System.out.println("Demox还剩: " + Gril.money);
                    break;
                }
            }
        }

    }

}

class Gril extends Thread {
    public static int money = 10;

    @Override
    public void run() {
        try {
            Thread.sleep(10);
            money -= 5;
            System.out.println("Gril还剩" + money);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}